
package SSF.Util.Streams.example;
import SSF.Util.Streams.*;

class Example {

    public static String stream_name = "Anything you like here";
    public static String stream_file = "file:/tmp/stream.example";

    public static void main(String[] argv) {

	try {
	    
	    StreamInterface recorder = new BasicRecorder(stream_name);
	    
	    recorder.connectWrite(stream_file);
	    
	    String writer1 = "1(0)";
	    String writer2 = "2(0)";
	    String writer3 = "3(0)";
	    
	    int writer1c = recorder.getRecordSourceCode(writer1);
	    int writer2c = recorder.getRecordSourceCode(writer2);
	    int writer3c = recorder.getRecordSourceCode(writer3);

	    String type1  = "foo";
	    String type2  = "bar";
	    String type3  = "baz";

	    int type1c = recorder.getRecordTypeCode(type1);
	    int type2c = recorder.getRecordTypeCode(type2);
	    int type3c = recorder.getRecordTypeCode(type3);
	    
	    for (int n=0; n<100; n++) {
		byte[] bset = ("payload #"+n).getBytes();

		if (0 == n%7)  
		    recorder.send(type1c,writer1c,n*10.,bset,0,bset.length);

		if (0 == n%13) 
		    recorder.send(type2c,writer2c,n*10.,bset,0,bset.length);

		if (0 == n%19) 
		    recorder.send(type3c,writer3c,n*10.,bset,0,bset.length);
	    }

	    recorder.disconnect();

	} catch (streamException strex) {
	    System.err.println(strex);
	    System.exit(-1);
	}


	//-----------------------------------------------------------

	try {

	    StreamInterface player = new BasicPlayer(stream_name);

	    player.connectRead(stream_file);  // receives all records
	    
	} catch (streamException strex) {
	    System.err.println(strex);
	    System.exit(-1);
	}
	
	//-----------------------------------------------------------
    }

}

